package com.atguigu3.common_algorithm.exer4;

/**
 * @author lhl
 * @date 2025/3/31 11:26
 */
public class ArrayExer04_1 {
    public static void main(String[] args) {
        //1.声明array1和array2两个变量,并将array1初始化为8个素数:2,3,5,7,11,13,17,19
        int[] array1 = {2,3,5,7,11,13,17,19};
        int[] array2 = new int[array1.length];
        //2.显示array1的内容。
        for (int i = 0; i < array1.length; i++) {
            System.out.print("修改前："+array1[i]+"\t");
        }

        //3.复制array1数组给array2，修改array2中的偶索引元素，使其等于索引值(如array[0]=0,array[2]=2)
        for (int i = 0; i < array2.length; i++) {
            array2[i] = array1[i];
        }

        //4.修改array2中的偶索引元素，使其等于索引值(如array[0]=0,array[2]=2)
        for (int i = 0; i < array2.length; i++) {
            if (i % 2 == 0) array2[i] = i;
        }

        System.out.println();
        System.out.println(array1);
        System.out.println(array2);

        for (int i = 0; i < array1.length; i++) {
            System.out.print("修改后："+array1[i]+"\t");
        }
    }
}
